package com.kuang.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Locale;

@Configuration //让这个类变成一个配置类
@EnableWebMvc //继承原有mvc，扩展mvc
public class MyMvcConfig implements WebMvcConfigurer {
    //实现了视图解析器接口的类，就可以叫做视图解析器
    @Bean //表示返回一个bean对象
    public ViewResolver myViewResolver(){
        return new MyViewResolver();
    }
    //自定义了一个自己的视图解析器myViewResolver
    public static class MyViewResolver implements ViewResolver{
        @Override
        public View resolveViewName(String viewName, Locale locale) throws Exception {
            return null;
        }
    }
    //视图跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
//        WebMvcConfigurer.super.addViewControllers(registry);
        registry.addViewController("/kuang").setViewName("test"); //访问这个http://127.0.0.1:8081/kuang 得出来的是test模板中的内容,url还是kuang的
    }
}
